<template>
	<view class="flex-col page">
		<view class="flex-col flex-auto group">
			<picker @change="pickerChange" :value="index" :range="array">
				<view class="flex-row justify-between section_3">
					<text class="font_2">营业状态</text>
					<view class="flex-row items-center space-x-20">
						<text class="text_4">{{array[index]}}</text>
						<image class="shrink-0 image_6" src="/static/more1.png" />
					</view>
				</view>
			</picker>
			<view class="flex-row justify-between items-center section_3" @click="toTime">
				<text class="font_2">营业时间段</text>
				<image class="image_6" src="/static/more1.png" />
			</view>
		</view>
	</view>
</template>

<script setup>
	import {
		onShow
	} from "@dcloudio/uni-app";
	import {
		onMounted,
		ref,
		reactive,
		getCurrentInstance
	} from "vue"
	const {
		proxy
	} = getCurrentInstance()
	let shop_id = ref('')
	let index = ref(0)
	let array = ref(['不营业', '营业']);

	onShow(() => {
		if (uni.getStorageSync('shop_id')) {
			shop_id.value = uni.getStorageSync('shop_id')
			getDate()
		} else {
			shop_id.value = ''
		}

	})
	const getDate = () => {
		proxy.$req.requestPOST(proxy.$api.CenterInfo.getInfo,{
			shop_id:uni.getStorageSync('shop_id'),
		}).then(res => {
			if (res.flag == "success") {
				index.value = res.data.is_on
			}else{
				uni.showToast({
					title:res.message,
					icon:"none"
				})
			}
		})
	}
	const pickerChange = (e) => {
		proxy.$req.requestPOST(proxy.$api.CenterInfo.setOn, {
			shop_id: uni.getStorageSync('shop_id'),
			is_on: e.detail.value
		}).then(res => {
			console.log(res);
			uni.showToast({
				title: res.message,
				icon: "none"
			})
			if (res.flag == "success") {
				index.value = e.detail.value
			}
		})
	}
	const toNotSign = () => {
		uni.removeStorageSync('shop_id')
		uni.showToast({
			title: '退出成功！',
			icon: 'none'
		})
		setTimeout(() => {
			uni.navigateBack()
		}, 1500)
	}
	const toLogin = () => {
		uni.navigateTo({
			url: '/pages/login/login'
		})
	}

	const toTime = () => {
		uni.navigateTo({
			url: '/pages/time/time'
		})
	}
</script>


<style scoped lang="scss">
	.page {
		background-color: #f8f8f8;
		width: 100%;
		overflow-y: auto;
		overflow-x: hidden;
		height: 100%;

		.group {
			padding-bottom: 1238rpx;
			overflow-y: auto;

			.section_3 {
				padding: 38rpx 30rpx;
				background-color: #ffffff;

				.font_2 {
					font-size: 28rpx;
					font-family: PingFangSC;
					line-height: 27rpx;
					color: #333333;
				}

				.space-x-20 {

					&>view:not(:first-child),
					&>text:not(:first-child),
					&>image:not(:first-child) {
						margin-left: 20rpx;
					}

					.text_4 {
						color: #333333;
						font-size: 28rpx;
						font-family: PingFangHeiTC;
						line-height: 26rpx;
					}
				}

				.image_6 {
					width: 9rpx;
					height: 18rpx;
				}
			}
		}
	}
</style>